package cn.afactory.tygz.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.harwkin.nb.camera.BaseImgView;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.model.CompanyInfo;
import cn.afactory.tygz.model.SnsTopicInfo;

/**
 * Created by Kenneth on 15/9/29.
 */
public class CompanyListAdapter extends BaseAdapter {

    private List<CompanyInfo> mList = new ArrayList<CompanyInfo>();
    private Context mContext;

    public CompanyListAdapter(Context ctx, List<CompanyInfo> list) {
        mList = list;
        mContext = ctx;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        CompanyInfo companyInfo = mList.get(position);
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_company_list,null);

//            holder.companyIcon = (ImageView)convertView.findViewById(R.id.company_icon);
            holder.companyName = (TextView)convertView.findViewById(R.id.company_name);
//            holder.companyPeople = (TextView)convertView.findViewById(R.id.company_people);
//            holder.companyDes = (TextView)convertView.findViewById(R.id.company_des);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }

//        if (companyInfo.topicIcon != null && companyInfo.topicIcon.length() > 0) {
//            BaseImgView.loadimg(holder.companyIcon, companyInfo.topicIcon, R.drawable.ic_user_default,
//                    R.drawable.ic_pic_loading_default_small, R.drawable.ic_pic_loading_default_small, ImageScaleType.EXACTLY,
//                    (int) mContext.getResources().getDimension(R.dimen.healthcircle_padding30),
//                    (int) mContext.getResources().getDimension(R.dimen.healthcircle_padding30),
//                    0);
//        } else {
//            holder.companyIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_pic_loading_default_small));
//        }

        if(!TextUtils.isEmpty(companyInfo.companyName)){
            holder.companyName.setText(companyInfo.companyName);
        } else {
            holder.companyName.setText("");
        }

//        if(!TextUtils.isEmpty(companyInfo.companyName)){
//            holder.companyPeople.setText("员工  29023人");
//        } else {
//            holder.companyPeople.setText("");
//        }
//
//        if(!TextUtils.isEmpty(companyInfo.companyName)){
//            holder.companyDes.setText(companyInfo.companyName);
//        } else {
//            holder.companyDes.setText("");
//        }

        return convertView;
    }


    public void setData(List<CompanyInfo> data) {
        this.mList = data;
        notifyDataSetChanged();
    }

    static class ViewHolder{
//        public ImageView companyIcon;
        public TextView companyName;
        public TextView companyPeople;
        public TextView companyDes;
    }
}